package com.selfdriving.utils;

import net.tsz.afinal.FinalHttp;
import net.tsz.afinal.http.AjaxCallBack;
import net.tsz.afinal.http.AjaxParams;

import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import com.selfdriving.activity.ActivityFriendsMsgQuery;

public class ServiceUtils
{
	public static void post(final Context context, final String phone)
	{
		Utils.showLoadingDialog(context, "好友查询中...");
		AjaxParams params = new AjaxParams();
		params.put("f", "65");
		params.put("phone", phone);
		FinalHttp fh = new FinalHttp();
		fh.configTimeout(20000);
		fh.post(Constant.POST, params, new AjaxCallBack<Object>()
		{
			@Override
			public void onFailure(Throwable t, String strMsg)
			{
				Utils.dismissLoadingDialog();
				Utils.showShortToast(context, "服务器异常");
			}

			@Override
			public void onSuccess(Object o)
			{
				String json = o.toString();
				try
				{
					JSONObject object = new JSONObject(json);
					String headImg = object.getString("headImg");
					String name = object.getString("name");
					String sex = object.getString("sex");
					String sign = object.getString("sign");
					String age = object.getString("age");
					String carNum = object.getString("carNum");
					String birthday = object.getString("birthday");
					String status = object.getString("status");
					String regDate = object.getString("regDate");
					Utils.dismissLoadingDialog();
					String datas[] = new String[10];
					datas[0] = headImg;
					datas[1] = name;
					datas[2] = sex;
					datas[3] = sign;
					datas[4] = age;
					datas[5] = carNum;
					datas[6] = birthday;
					datas[7] = status;
					datas[8] = regDate;
					datas[9] = phone;
					Bundle bundle = new Bundle();
					bundle.putStringArray("datas", datas);
					Intent intent = new Intent(context,
							ActivityFriendsMsgQuery.class);
					intent.putExtra("bundle", bundle);
					context.startActivity(intent);
				} catch (JSONException e)
				{
					Utils.dismissLoadingDialog();
					Utils.showShortToast(context, "没找到好友");
					e.printStackTrace();
				}
			}
		});
	}
}
